package cn.terminus.web.customer.contractselldefylatedeliveryinfo.controller;

import cn.terminus.web.customer.contractselldefylatedeliveryinfo.form.ContractSellDefyLateDeliveryInfoNewForm;
import cn.terminus.web.customer.contractselldefylatedeliveryinfo.form.ContractSellDefyLateDeliveryInfoEditForm;
import cn.terminus.web.customer.contractselldefylatedeliveryinfo.form.ContractSellDefyLateDeliveryInfoQueryForm;
import cn.terminus.web.customer.contractselldefylatedeliveryinfo.form.ContractSellDefyLateDeliveryInfoDeleteForm;
import cn.terminus.web.customer.contractselldefylatedeliveryinfo.form.ContractSellDefyLateDeliveryInfoGetsForm;
import cn.terminus.client.customer.contractselldefylatedeliveryinfo.param.ContractSellDefyLateDeliveryInfoNewParam;
import cn.terminus.client.customer.contractselldefylatedeliveryinfo.param.ContractSellDefyLateDeliveryInfoEditParam;
import cn.terminus.client.customer.contractselldefylatedeliveryinfo.param.ContractSellDefyLateDeliveryInfoQueryParam;
import cn.terminus.client.customer.contractselldefylatedeliveryinfo.param.ContractSellDefyLateDeliveryInfoDeleteParam;
import cn.terminus.client.customer.contractselldefylatedeliveryinfo.param.ContractSellDefyLateDeliveryInfoGetsParam;
import cn.terminus.client.customer.contractselldefylatedeliveryinfo.result.ContractSellDefyLateDeliveryInfoResult;
import cn.terminus.client.customer.contractselldefylatedeliveryinfo.service.ContractSellDefyLateDeliveryInfoService;
import cn.terminus.result.common.result.TerminusResult;
import cn.terminus.result.common.page.TerminusPageAble;
import cn.terminus.result.common.page.TerminusPageInfo;
import cn.terminus.web.customer.common.AbstractTerminusController;
import cn.terminus.result.common.exception.DataAccessException;
import cn.terminus.result.common.exception.ServiceException;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import cn.terminus.result.common.util.BeanCopyUtils;
import cn.terminus.result.common.context.TerminusCallContext;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import javax.annotation.Resource;
import java.util.List;

/**
 * 合同售卖交付违约(ContractSellDefyLateDeliveryInfo)控制层
 *
 * @author makejava
 * @version 1.0.0
 * @apiDefine ContractSellDefyLateDeliveryInfo 合同售卖交付违约
 * @since 2021-07-21 11:18:00
 */
@RestController
// todo 请修改path
@RequestMapping("/contractSellDefyLateDeliveryInfo")
@Api(value = "合同售卖交付违约(ContractSellDefyLateDeliveryInfo)控制层")
public class ContractSellDefyLateDeliveryInfoController extends AbstractTerminusController {
    /**
     * 服务对象
     */
    @Resource
    private ContractSellDefyLateDeliveryInfoService contractSellDefyLateDeliveryInfoService;

    /**
     * @api {POST} /contractSellDefyLateDeliveryInfo/add 合同售卖交付违约新增
     * @apiVersion 1.0.0
     * @apiGroup ContractSellDefyLateDeliveryInfo
     * @apiName 合同售卖交付违约新增
     * @apiDescription 合同售卖交付违约新增
     * @apiParam (RequestBody) {Long} contractId  合同ID
     * @apiParam (RequestBody) {Integer} lateDeliveryWithinDay  付款逾期多少日内
     * @apiParam (RequestBody) {String} lateDeliveryWithinDayUnitCode  付款逾期(内)日期类型
     * @apiParam (RequestBody) {Double} lateDeliveryOverduePaymentPercentage  按日支付逾期应付百分数
     * @apiParam (RequestBody) {Integer} lateDeliveryOverDay  逾期超多少日
     * @apiParam (RequestBody) {String} lateDeliveryOverDayUnitCode  逾期(超过)日期类型
     * @apiParam (RequestBody) {Integer} lateDeliveryPermitCancelDay  客户可在多少日内解除合同
     * @apiParam (RequestBody) {String} lateDeliveryPermitCancelDayUnitCode  客户可在多少日内解除合同 日期类型字典code
     * @apiParam (RequestBody) {Double} cancelContractPayPercentage  解除合同支付违约金（总价款的百分数）
     * @apiParam (RequestBody) {Integer} continueContractPayPercentageWithDay  继续履行合同，按日支付逾期应付（总价款的百分数）
     * @apiSuccess (Success 200) {String} code    状态码（00000000表示请求成功）
     * @apiSuccess (Success 200) {Boolean} success    成功
     * @apiSuccess (Success 200) {String} message    结果消息
     * @apiSuccess (Success 200) {String} data    结果
     * @apiSuccessExample {json} 请求成功返回值:
     * {"code":"00000000","success":true,"message":"成功","data":"[]"}
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ApiOperation(value = "合同售卖交付违约新增", httpMethod = "POST")
    public TerminusResult<String> add(@RequestBody ContractSellDefyLateDeliveryInfoNewForm form) {
        ContractSellDefyLateDeliveryInfoNewParam param = BeanCopyUtils.copyProperties(form, ContractSellDefyLateDeliveryInfoNewParam.class);
        try {
            return contractSellDefyLateDeliveryInfoService.add(param, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("新增合同售卖交付违约失败，原因：", e);
            return TerminusResult.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("新增合同售卖交付违约失败，原因：", e);
            //todo 修改错误码
            return TerminusResult.fail("", this.getMessage(""));
        }
    }


    /**
     * @api {POST} /contractSellDefyLateDeliveryInfo/edit 合同售卖交付违约编辑
     * @apiVersion 1.0.0
     * @apiGroup ContractSellDefyLateDeliveryInfo
     * @apiName 合同售卖交付违约编辑
     * @apiDescription 合同售卖交付违约编辑
     * @apiParam (RequestBody) {Long} id  ID
     * @apiParam (RequestBody) {Long} contractId  合同ID
     * @apiParam (RequestBody) {Integer} lateDeliveryWithinDay  付款逾期多少日内
     * @apiParam (RequestBody) {String} lateDeliveryWithinDayUnitCode  付款逾期(内)日期类型
     * @apiParam (RequestBody) {Double} lateDeliveryOverduePaymentPercentage  按日支付逾期应付百分数
     * @apiParam (RequestBody) {Integer} lateDeliveryOverDay  逾期超多少日
     * @apiParam (RequestBody) {String} lateDeliveryOverDayUnitCode  逾期(超过)日期类型
     * @apiParam (RequestBody) {Integer} lateDeliveryPermitCancelDay  客户可在多少日内解除合同
     * @apiParam (RequestBody) {String} lateDeliveryPermitCancelDayUnitCode  客户可在多少日内解除合同 日期类型字典code
     * @apiParam (RequestBody) {Double} cancelContractPayPercentage  解除合同支付违约金（总价款的百分数）
     * @apiParam (RequestBody) {Integer} continueContractPayPercentageWithDay  继续履行合同，按日支付逾期应付（总价款的百分数）
     * @apiSuccess (Success 200) {String} code    状态码（00000000表示请求成功）
     * @apiSuccess (Success 200) {Boolean} success    成功
     * @apiSuccess (Success 200) {String} message    结果消息
     * @apiSuccess (Success 200) {Object} data    结果
     * @apiSuccessExample {json} 请求成功返回值:
     * {"code":"00000000","success":true,"message":"成功","data":true}
     */

    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    @ApiOperation(value = "合同售卖交付违约编辑", httpMethod = "POST")
    public TerminusResult<Boolean> edit(@RequestBody ContractSellDefyLateDeliveryInfoEditForm form) {
        ContractSellDefyLateDeliveryInfoEditParam param = BeanCopyUtils.copyProperties(form, ContractSellDefyLateDeliveryInfoEditParam.class);
        try {
            return contractSellDefyLateDeliveryInfoService.update(param, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("修改合同售卖交付违约失败，原因：", e);
            return TerminusResult.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("修改合同售卖交付违约失败，原因：", e);
            //todo 修改错误码
            return TerminusResult.fail("", this.getMessage(""));
        }
    }

    /**
     * @api {POST} /contractSellDefyLateDeliveryInfo/delete 合同售卖交付违约删除
     * @apiVersion 1.0.0
     * @apiGroup ContractSellDefyLateDeliveryInfo
     * @apiName 合同售卖交付违约删除
     * @apiDescription 合同售卖交付违约删除
     * @apiParam (RequestBody) {String[]} ids  合同售卖交付违约ids
     * @apiSuccess (Success 200) {Object} data    结果
     * @apiSuccessExample {json} 请求成功返回值:
     * {"code":"00000000","success":true,"message":"成功","data":true}
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ApiOperation(value = "合同售卖交付违约删除", httpMethod = "POST")
    public TerminusResult<Boolean> delete(@RequestBody ContractSellDefyLateDeliveryInfoDeleteForm form) {
        ContractSellDefyLateDeliveryInfoDeleteParam param = BeanCopyUtils.copyProperties(form, ContractSellDefyLateDeliveryInfoDeleteParam.class);
        try {
            return contractSellDefyLateDeliveryInfoService.delete(param, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("删除合同售卖交付违约失败，原因：", e);
            return TerminusResult.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("删除合同售卖交付违约失败，原因：", e);
            //todo 修改错误码
            return TerminusResult.fail("", this.getMessage(""));
        }
    }

    /**
     * @api {POST} /contractSellDefyLateDeliveryInfo/gets 合同售卖交付违约详情
     * @apiVersion 1.0.0
     * @apiGroup ContractSellDefyLateDeliveryInfo
     * @apiName 合同售卖交付违约详情
     * @apiDescription 合同售卖交付违约详情
     * @apiParam (RequestBody) {String[]} ids  合同售卖交付违约ids
     * @apiSuccess (Success 200) {Object} data    结果
     * @apiSuccess (Success 200) {Object[]} data.datas    合同售卖交付违约列表
     * @apiSuccess (Success 200) {Long} data.datas.id  ID
     * @apiSuccess (Success 200) {Long} data.datas.contractId  合同ID
     * @apiSuccess (Success 200) {Integer} data.datas.lateDeliveryWithinDay  付款逾期多少日内
     * @apiSuccess (Success 200) {String} data.datas.lateDeliveryWithinDayUnitCode  付款逾期(内)日期类型
     * @apiSuccess (Success 200) {Double} data.datas.lateDeliveryOverduePaymentPercentage  按日支付逾期应付百分数
     * @apiSuccess (Success 200) {Integer} data.datas.lateDeliveryOverDay  逾期超多少日
     * @apiSuccess (Success 200) {String} data.datas.lateDeliveryOverDayUnitCode  逾期(超过)日期类型
     * @apiSuccess (Success 200) {Integer} data.datas.lateDeliveryPermitCancelDay  客户可在多少日内解除合同
     * @apiSuccess (Success 200) {String} data.datas.lateDeliveryPermitCancelDayUnitCode  客户可在多少日内解除合同 日期类型字典code
     * @apiSuccess (Success 200) {Double} data.datas.cancelContractPayPercentage  解除合同支付违约金（总价款的百分数）
     * @apiSuccess (Success 200) {Integer} data.datas.continueContractPayPercentageWithDay  继续履行合同，按日支付逾期应付（总价款的百分数）
     * @apiSuccessExample {json} 请求成功返回值:
     * {"code":"00000000","success":true,"message":"成功","data":[]}
     */
    @RequestMapping(value = "/gets", method = RequestMethod.POST)
    @ApiOperation(value = "合同售卖交付违约详情查询", httpMethod = "POST")
    public TerminusResult<List<ContractSellDefyLateDeliveryInfoResult>> gets(@RequestBody ContractSellDefyLateDeliveryInfoGetsForm form) {
        ContractSellDefyLateDeliveryInfoGetsParam param = BeanCopyUtils.copyProperties(form, ContractSellDefyLateDeliveryInfoGetsParam.class);
        try {
            return contractSellDefyLateDeliveryInfoService.gets(param, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("查询合同售卖交付违约失败，原因：", e);
            return TerminusResult.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("查询合同售卖交付违约失败，原因：", e);
            //todo 修改错误码
            return TerminusResult.fail("", this.getMessage(""));
        }
    }

    /**
     * @api {POST} /contractSellDefyLateDeliveryInfo/query 合同售卖交付违约查询
     * @apiVersion 1.0.0
     * @apiGroup ContractSellDefyLateDeliveryInfo
     * @apiName 合同售卖交付违约查询
     * @apiDescription 合同售卖交付违约查询
     * @apiParam (RequestBody) {Long} contractId  合同ID
     * @apiParam (RequestBody) {Integer} lateDeliveryWithinDay  付款逾期多少日内
     * @apiParam (RequestBody) {String} lateDeliveryWithinDayUnitCode  付款逾期(内)日期类型
     * @apiParam (RequestBody) {Double} lateDeliveryOverduePaymentPercentage  按日支付逾期应付百分数
     * @apiParam (RequestBody) {Integer} lateDeliveryOverDay  逾期超多少日
     * @apiParam (RequestBody) {String} lateDeliveryOverDayUnitCode  逾期(超过)日期类型
     * @apiParam (RequestBody) {Integer} lateDeliveryPermitCancelDay  客户可在多少日内解除合同
     * @apiParam (RequestBody) {String} lateDeliveryPermitCancelDayUnitCode  客户可在多少日内解除合同 日期类型字典code
     * @apiParam (RequestBody) {Double} cancelContractPayPercentage  解除合同支付违约金（总价款的百分数）
     * @apiParam (RequestBody) {Integer} continueContractPayPercentageWithDay  继续履行合同，按日支付逾期应付（总价款的百分数）
     * @apiSuccess (Success 200) {Object} data    结果
     * @apiSuccess (Success 200) {Object[]} data.datas    合同售卖交付违约列表
     * @apiSuccess (Success 200) {Long} data.datas.id  ID
     * @apiSuccess (Success 200) {Long} data.datas.contractId  合同ID
     * @apiSuccess (Success 200) {Integer} data.datas.lateDeliveryWithinDay  付款逾期多少日内
     * @apiSuccess (Success 200) {String} data.datas.lateDeliveryWithinDayUnitCode  付款逾期(内)日期类型
     * @apiSuccess (Success 200) {Double} data.datas.lateDeliveryOverduePaymentPercentage  按日支付逾期应付百分数
     * @apiSuccess (Success 200) {Integer} data.datas.lateDeliveryOverDay  逾期超多少日
     * @apiSuccess (Success 200) {String} data.datas.lateDeliveryOverDayUnitCode  逾期(超过)日期类型
     * @apiSuccess (Success 200) {Integer} data.datas.lateDeliveryPermitCancelDay  客户可在多少日内解除合同
     * @apiSuccess (Success 200) {String} data.datas.lateDeliveryPermitCancelDayUnitCode  客户可在多少日内解除合同 日期类型字典code
     * @apiSuccess (Success 200) {Double} data.datas.cancelContractPayPercentage  解除合同支付违约金（总价款的百分数）
     * @apiSuccess (Success 200) {Integer} data.datas.continueContractPayPercentageWithDay  继续履行合同，按日支付逾期应付（总价款的百分数）
     * @apiSuccessExample {json} 请求成功返回值:
     * {"code":"00000000","success":true,"message":"成功","data":[]}
     */
    @RequestMapping(value = "/query", method = RequestMethod.POST)
    @ApiOperation(value = "合同售卖交付违约查询", httpMethod = "POST")
    public TerminusResult<List<ContractSellDefyLateDeliveryInfoResult>> query(@RequestBody ContractSellDefyLateDeliveryInfoQueryForm form) {
        ContractSellDefyLateDeliveryInfoQueryParam param = BeanCopyUtils.copyProperties(form, ContractSellDefyLateDeliveryInfoQueryParam.class);
        try {
            return contractSellDefyLateDeliveryInfoService.query(param, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("查询合同售卖交付违约失败，原因：", e);
            return TerminusResult.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("查询合同售卖交付违约失败，原因：", e);
            //todo 修改错误码
            return TerminusResult.fail("", this.getMessage(""));
        }
    }

    /**
     * @api {POST} /contractSellDefyLateDeliveryInfo/page 合同售卖交付违约分页查询
     * @apiVersion 1.0.0
     * @apiGroup ContractSellDefyLateDeliveryInfo
     * @apiName 合同售卖交付违约分页查询
     * @apiDescription 合同售卖交付违约分页查询
     * @apiParam (RequestBody) {Long} contractId  合同ID
     * @apiParam (RequestBody) {Integer} lateDeliveryWithinDay  付款逾期多少日内
     * @apiParam (RequestBody) {String} lateDeliveryWithinDayUnitCode  付款逾期(内)日期类型
     * @apiParam (RequestBody) {Double} lateDeliveryOverduePaymentPercentage  按日支付逾期应付百分数
     * @apiParam (RequestBody) {Integer} lateDeliveryOverDay  逾期超多少日
     * @apiParam (RequestBody) {String} lateDeliveryOverDayUnitCode  逾期(超过)日期类型
     * @apiParam (RequestBody) {Integer} lateDeliveryPermitCancelDay  客户可在多少日内解除合同
     * @apiParam (RequestBody) {String} lateDeliveryPermitCancelDayUnitCode  客户可在多少日内解除合同 日期类型字典code
     * @apiParam (RequestBody) {Double} cancelContractPayPercentage  解除合同支付违约金（总价款的百分数）
     * @apiParam (RequestBody) {Integer} continueContractPayPercentageWithDay  继续履行合同，按日支付逾期应付（总价款的百分数）
     * @apiSuccess (Success 200) {Object} data    结果
     * @apiSuccess (Success 200) {long} data.pageSize    分页大小
     * @apiSuccess (Success 200) {long} data.currentPage    当前页
     * @apiSuccess (Success 200) {long} data.totalPages    总页数
     * @apiSuccess (Success 200) {long} data.totalRows    总记录数
     * @apiSuccess (Success 200) {long} data.minRowNumber    当页起始行号
     * @apiSuccess (Success 200) {long} data.maxRowNumber    当页最大行号
     * @apiSuccess (Success 200) {Object[]} data.datas    合同售卖交付违约列表
     * @apiSuccess (Success 200) {Long} data.datas.id  ID
     * @apiSuccess (Success 200) {Long} data.datas.contractId  合同ID
     * @apiSuccess (Success 200) {Integer} data.datas.lateDeliveryWithinDay  付款逾期多少日内
     * @apiSuccess (Success 200) {String} data.datas.lateDeliveryWithinDayUnitCode  付款逾期(内)日期类型
     * @apiSuccess (Success 200) {Double} data.datas.lateDeliveryOverduePaymentPercentage  按日支付逾期应付百分数
     * @apiSuccess (Success 200) {Integer} data.datas.lateDeliveryOverDay  逾期超多少日
     * @apiSuccess (Success 200) {String} data.datas.lateDeliveryOverDayUnitCode  逾期(超过)日期类型
     * @apiSuccess (Success 200) {Integer} data.datas.lateDeliveryPermitCancelDay  客户可在多少日内解除合同
     * @apiSuccess (Success 200) {String} data.datas.lateDeliveryPermitCancelDayUnitCode  客户可在多少日内解除合同 日期类型字典code
     * @apiSuccess (Success 200) {Double} data.datas.cancelContractPayPercentage  解除合同支付违约金（总价款的百分数）
     * @apiSuccess (Success 200) {Integer} data.datas.continueContractPayPercentageWithDay  继续履行合同，按日支付逾期应付（总价款的百分数）
     * @apiSuccessExample {json} 请求成功返回值:
     * {"code":"00000000","success":true,"message":"成功","data":[]}
     */
    @RequestMapping(value = "/page", method = RequestMethod.POST)
    @ApiOperation(value = "合同售卖交付违约分页查询", httpMethod = "POST")
    public TerminusResult<TerminusPageAble<ContractSellDefyLateDeliveryInfoResult>> page(@RequestBody ContractSellDefyLateDeliveryInfoQueryForm form) {
        ContractSellDefyLateDeliveryInfoQueryParam param = BeanCopyUtils.copyProperties(form, ContractSellDefyLateDeliveryInfoQueryParam.class);
        try {
            TerminusPageInfo page = new TerminusPageInfo(form.getCurrentPage(), form.getRowsOfPage());
            return contractSellDefyLateDeliveryInfoService.page(param, page, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("分页查询合同售卖交付违约失败，原因：", e);
            return TerminusResult.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("分页查询合同售卖交付违约失败，原因：", e);
            //todo 修改错误码
            return TerminusResult.fail("", this.getMessage(""));
        }
    }

}
